-- VIEWS
create view MyObjects as select * from user_objects;
create view MyEMP as select emp.ename, dept.dname from dept, emp where dept.deptno = emp.deptno;

-- METHODS

create or replace
Function GetTvoid(type_oid IN RAW, vsn IN PLS_INTEGER) return
                    RAW AS
 tv_oid RAW(16);
begin
 select tvoid into tv_oid from type$ where toid = type_oid and
   version# = vsn;
 return (tv_oid);
end;

create or replace
function instance_num return binary_integer is
begin
return dbms_standard.instance_num;
end;

create or replace
function login_user return varchar2 is
begin
return dbms_standard.login_user;
end;

create or replace
PROCEDURE load_undo_stat(qlen IN NUMBER, ubks IN NUMBER)
IS
  loadsql varchar2(1024);
  val     number;
  cid     number;
  rows    integer;
BEGIN
  val := ubks * 100000 + qlen + 100;
  loadsql := 'alter system set "_undo_debug_usage" = ' || val;
  dbms_output.put_line(loadsql);
  cid := dbms_sql.open_cursor;
  dbms_sql.parse(cid, loadsql, dbms_sql.native);
  rows := dbms_sql.execute(cid);
  dbms_sql.close_cursor(cid);
END load_undo_stat;

create or replace
procedure DBMS_FEATURE_EXADATA
    (feature_boolean  OUT  NUMBER,
     num_cells        OUT  NUMBER,
     feature_info     OUT  CLOB)
AS
  feature_usage          varchar2(1000);
begin
  -- initialize
  num_cells := 0;
  feature_boolean := 0;
  feature_info := to_clob('EXADATA usage not detected');
  feature_usage := '';

  execute immediate 'select count(*) from (select distinct cell_name from gv$cell_state)'
  into num_cells;

  if num_cells > 0
  then

    feature_boolean := 1;

    feature_usage := feature_usage||':cells:'||num_cells;

    feature_info := to_clob(feature_usage);

  end if;

end;

-- PACKAGE

create or replace
PACKAGE dbms_job IS

  -- for backward compatibility. Not used anymore.
  any_instance CONSTANT BINARY_INTEGER := 0;

  -- Parameters are:
  --
  -- JOB is the number of the job being executed.
  -- WHAT is the PL/SQL procedure to execute.
  --   The job must always be a single call to a procedure.  The
  --     routine may take any number of hardcoded parameters.
  --     Special parameter values recognized are:
  --       job:       an in parameter, the number of the current job
  --       next_date: in/out, the date of the next refresh
  --       broken:    in/out, is the job broken.  The IN values is FALSE.
  --   Always remember the trailing semicolon.
  --   Some legal values of WHAT (assuming the routines exist) are
  --     'myproc( ''10-JAN-82'', next_date, broken);'
  --     'scott.emppackage.give_raise( ''JENKINS'', 30000.00);'
  --     'dbms_job.remove( job);'
  -- NEXT_DATE is the date at which the job will next be automatically run,
  --   assuming there are background processes attempting to run it.
  -- INTERVAL is a date function, evaluated immediately before the job starts
  --   executing.  If the job completes successfully, this new date is placed
  --   in NEXT_DATE.  INTERVAL is evaluated by plugging it into the statement
  --     select INTERVAL into next_date from dual;
  --   INTERVAL must evaluate to a time in the future.  Legal intervals include
  --     'sysdate + 7'                    -- execute once a week
  --     'NEXT_DAY(sysdate,''TUESDAY'')'  -- execute once every tuesday
  --     'null'                           -- only execute once
  --   If INTERVAL evaluates to null and a job completes successfully, then
  --   the job is automatically deleted from the queue.

  PROCEDURE isubmit    ( job       IN  BINARY_INTEGER,
                         what      IN  VARCHAR2,
                         next_date IN  DATE,
                         interval  IN  VARCHAR2 DEFAULT 'null',
                         no_parse  IN  BOOLEAN DEFAULT FALSE);
  -- Submit a new job with a given job number.

  PROCEDURE submit    ( job       OUT BINARY_INTEGER,
                        what      IN  VARCHAR2,
                        next_date IN  DATE DEFAULT sysdate,
                        interval  IN  VARCHAR2 DEFAULT 'null',
                        no_parse  IN  BOOLEAN DEFAULT FALSE,

                        -- Bug 1346620: replace pkg vars with constants.
                        -- Default for instance = dbms_job.any_instance.
			instance  IN  BINARY_INTEGER DEFAULT 0,
			force     IN  BOOLEAN DEFAULT FALSE );
  -- Submit a new job.  Chooses JOB from the sequence sys.jobseq.
  -- instance and force are added for jobq queue affinity
  -- If FORCE is TRUE, then any positive  integer is acceptable as the job
  -- instance. If FORCE is FALSE, then the specified instance must be running;
  -- otherwise the routine raises an exception.
  -- For example,
  --   variable x number;
  --   execute dbms_job.submit(:x,'pack.proc(''arg1'');',sysdate,'sysdate+1');

  PROCEDURE remove    ( job       IN  BINARY_INTEGER );
  -- Remove an existing job from the job queue.
  -- This currently does not stop a running job.
  --   execute dbms_job.remove(14144);

  PROCEDURE change    ( job       IN  BINARY_INTEGER,
                        what      IN  VARCHAR2,
                        next_date IN  DATE,
                        interval  IN  VARCHAR2,
			instance  IN  BINARY_INTEGER DEFAULT NULL,
			force     IN  BOOLEAN DEFAULT FALSE);
  -- Change any of the the user-settable fields in a job
  -- Parameter instance and force are added for job queue affinity
  -- If what, next_date,or interval is null, leave that value as-is.
  -- instance defaults to NULL indicates instance affinity is not changed.
  -- If FORCE is FALSE, the specified instance (to which the instance number
  -- change) must be running. Otherwise the routine raises an exception.
  -- If FORCE is TRUE, any positive  integer is acceptable as the job instance.
  --   execute dbms_job.change( 14144, null, null, 'sysdate+3');

  PROCEDURE what      ( job       IN  BINARY_INTEGER,
                        what      IN  VARCHAR2 );
  -- Change what an existing job does, and replace its environment

  PROCEDURE next_date ( job       IN  BINARY_INTEGER,
                        next_date IN  DATE     );
  -- Change when an existing job will next execute

  PROCEDURE instance ( job        IN BINARY_INTEGER,
                       instance   IN BINARY_INTEGER,
		       force      IN BOOLEAN DEFAULT FALSE);
  -- Change job instance affinity. FORCE parameter works same as in SUBMIT

  PROCEDURE interval  ( job       IN  BINARY_INTEGER,
                        interval  IN  VARCHAR2 );
  -- Change how often a job executes

  PROCEDURE broken    ( job       IN  BINARY_INTEGER,
                        broken    IN  BOOLEAN,
                        next_date IN  DATE DEFAULT SYSDATE );
  --  Set the broken flag.  Broken jobs are never run.

  PROCEDURE run       ( job       IN  BINARY_INTEGER,
			force     IN  BOOLEAN DEFAULT FALSE);
  --  Run job JOB now.  Run it even if it is broken.
  --  Running the job will recompute next_date, see view user_jobs.
  --    execute dbms_job.run(14144);
  --  Warning: this will reinitialize the current session's packages
  --  FORCE is added for job queue affinity
  --  If FORCE is TRUE, instance affinity is irrelevant for running jobs in
  --  the foreground process. If FORCE is FALSE, the job can be run in the
  --  foreground only in the specified instance. dbms_job.run will raise an
  --  exception if FORCE is FALSE and the connected instance is the wrong one.

  PROCEDURE user_export ( job    IN     BINARY_INTEGER,
                          mycall IN OUT VARCHAR2);
  --  Produce the text of a call to recreate the given job

  PROCEDURE user_export ( job     IN     BINARY_INTEGER,
                         mycall   IN OUT VARCHAR2,
			 myinst   IN OUT VARCHAR2);
  -- Procedure is added for altering instance affinity (8.1+) and perserve the
  -- compatibility

  --------------------------------------------------------------
  -- Return boolean value indicating whether execution is in background
  -- process or foreground process
  -- jobq processes are no longer background processes, background_processes
  -- will be removed in 8.3 or later
  -------------------------------------------------------------
  FUNCTION background_process RETURN BOOLEAN;
  FUNCTION is_jobq RETURN BOOLEAN;


END;


create or replace
PACKAGE BODY dbms_job wrapped
a000000
1
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
b
23d1 b7c
I8WDJTJmMs07TGNr9+F62uQ8C7Mwg5Wr3l4FYKAPamS030eFJ47QUhET4clgpzxgNSV71fqv
TyEaa+ugFPWp0nXuxv7N7dUMwq2DI+f3Dbu8T9tmX9xqrWBe02RQB/5PSPwPZBmMGrQxNeTr
znJzRQ4UFVLpf3sAENZOQ6btqF6JXRHsXahMPaGHBq3ohSSJ53Rsbheo4En1b2AEslFn4PYW
+gFzxGoge9BbpSj35X6lgorsaBSCZ4JH37V4CptNWVpKyaEcsVJUrHduXWVZWGHZyGBJqKT4
4wbCUa0GynCEY/XDzEJDnidH0+qTYfwCpqusKrBIucHO2I5b5LGvNkNc7OVOPkFJvkAuyYWF
TA5uiXYEjUm0pt4NjV1nZUHJ6Uw0LgeRN06rSG/b09cBC1W5+GZa4jYx6VqZcQfpTJR1ywSx
pkJ4H5wfJFVRE50gIm6ah92ynKn5aFW94Dj7hUN8SZFrVYZqKaunBz+8vJJGIs+tndLhjLoc
p/rTBa8YLyJtpaz4+aS05/NLjmLsM8KJr4nTexo44fzd/tMXBjyPQ849Cu0sNfQgehtLnx1x
amKcFxwFDw3Pf0DOajKiJcXZY/cz4bYE+TxUht2e/R/wxmvNUs9A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Ig+wmZwp7xTLpCzXoO6iSSlpbTvLs0XCDyXLpvtpV64hfeVw+u1/cT
AIvQYFc0GEmhXprBKg+h6FdOl4yVWECzKW7mzV/2uTtRtMpYQkPG2vDVnDnWC/pIynlNTfLn
bHd7qsk1yYVk+fvwtb1R
;








create or replace
PACKAGE dbms_random AUTHID DEFINER AS

    ------------
    --  OVERVIEW
    --
    --  This package should be installed as SYS.  It generates a sequence of
    --  random 38-digit Oracle numbers.  The expected length of the sequence
    --  is about power(10,28), which is hopefully long enough.
    --
    --------
    --  USAGE
    --
    --  This is a random number generator.  Do not use for cryptography.
    --  For more options the cryptographic toolkit should be used.
    --
    --  By default, the package is initialized with the current user
    --  name, current time down to the second, and the current session.
    --
    --  If this package is seeded twice with the same seed, then accessed
    --  in the same way, it will produce the same results in both cases.
    --
    --------
    --  EXAMPLES
    --
    --  To initialize or reset the generator, call the seed procedure as in:
    --      execute dbms_random.seed(12345678);
    --    or
    --      execute dbms_random.seed(TO_CHAR(SYSDATE,'MM-DD-YYYY HH24:MI:SS'));
    --  To get the random number, simply call the function, e.g.
    --      my_random_number BINARY_INTEGER;
    --      my_random_number := dbms_random.random;
    --    or
    --      my_random_real NUMBER;
    --      my_random_real := dbms_random.value;
    --  To use in SQL statements:
    --      select dbms_random.value from dual;
    --      insert into a values (dbms_random.value);
    --      variable x NUMBER;
    --      execute :x := dbms_random.value;
    --      update a set a2=a2+1 where a1 < :x;

    -- Seed with a binary integer
    PROCEDURE seed(val IN BINARY_INTEGER);
    PRAGMA restrict_references (seed, WNDS);

    -- Seed with a string (up to length 2000)
    PROCEDURE seed(val IN VARCHAR2);
    PRAGMA restrict_references (seed, WNDS);

    -- Get a random 38-digit precision number, 0.0 <= value < 1.0
    FUNCTION value RETURN NUMBER PARALLEL_ENABLE;
    PRAGMA restrict_references (value, WNDS);

    -- get a random Oracle number x, low <= x < high
    FUNCTION value (low IN NUMBER, high IN NUMBER) RETURN NUMBER
                   PARALLEL_ENABLE;
    PRAGMA restrict_references (value, WNDS);

    -- get a random number from a normal distribution
    FUNCTION normal RETURN NUMBER PARALLEL_ENABLE;
    PRAGMA restrict_references (normal, WNDS);

    -- get a random string
    FUNCTION string (opt char, len NUMBER)
          /* "opt" specifies that the returned string may contain:
             'u','U'  :  upper case alpha characters only
             'l','L'  :  lower case alpha characters only
             'a','A'  :  alpha characters only (mixed case)
             'x','X'  :  any alpha-numeric characters (upper)
             'p','P'  :  any printable characters
          */
        RETURN VARCHAR2 PARALLEL_ENABLE;  -- string of <len> characters
    PRAGMA restrict_references (string, WNDS);

    -- Obsolete, just calls seed(val)
    PROCEDURE initialize(val IN BINARY_INTEGER);
    PRAGMA restrict_references (initialize, WNDS);

    -- Obsolete, get integer in ( -power(2,31) <= random < power(2,31) )
    FUNCTION random RETURN BINARY_INTEGER PARALLEL_ENABLE;
    PRAGMA restrict_references (random, WNDS);

    -- Obsolete, does nothing
    PROCEDURE terminate;

    TYPE num_array IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
END dbms_random;



create or replace
PACKAGE BODY dbms_random AS
    mem        num_array;           -- big internal state hidden from the user
    counter    BINARY_INTEGER := 55;-- counter through the results
    saved_norm NUMBER := NULL;      -- unused random normally distributed value
    need_init  BOOLEAN := TRUE;     -- do we still need to initialize


    -- Seed the random number generator with a binary_integer
    PROCEDURE seed(val IN BINARY_INTEGER) IS
    BEGIN
	seed(TO_CHAR(val));
    END seed;


    -- Seed the random number generator with a string.
    PROCEDURE seed(val IN VARCHAR2) IS
        junk     VARCHAR2(2000);
        piece    VARCHAR2(20);
        randval  NUMBER;
        mytemp   NUMBER;
        j        BINARY_INTEGER;
    BEGIN
        need_init   := FALSE;
        saved_norm  := NULL;
        counter     := 0;
        junk        := TO_SINGLE_BYTE(val);
        FOR i IN 0..54 LOOP
            piece   := SUBSTR(junk,1,19);
            randval := 0;
            j       := 1;

            -- convert 19 characters to a 38-digit number
            FOR j IN 1..19 LOOP
                randval := 1e2*randval + NVL(ASCII(SUBSTR(piece,j,1)),0.0);
            END LOOP;

            -- try to avoid lots of zeros
            randval := randval*1e-38+i*.01020304050607080910111213141516171819;
            mem(i)  := randval - TRUNC(randval);

            -- we've handled these first 19 characters already; move on
            junk    := SUBSTR(junk,20);
        END LOOP;

	randval := mem(54);
        FOR j IN 0..10 LOOP
            FOR i IN 0..54 LOOP

                -- barrelshift mem(i-1) by 24 digits
                randval := randval * 1e24;
                mytemp  := TRUNC(randval);
                randval := (randval - mytemp) + (mytemp * 1e-38);

                -- add it to mem(i)
                randval := mem(i)+randval;
                IF (randval >= 1.0) THEN
                    randval := randval - 1.0;
                END IF;

		-- record the result
                mem(i) := randval;
            END LOOP;
        END LOOP;
    END seed;


    -- give values to the user
    -- Delayed Fibonacci, pilfered from Knuth volume 2
    FUNCTION value RETURN NUMBER  PARALLEL_ENABLE IS
    randval  NUMBER;
    BEGIN
        counter := counter + 1;
        IF counter >= 55 THEN

            -- initialize if needed
            IF (need_init = TRUE) THEN
                seed(TO_CHAR(SYSDATE,'MM-DD-YYYY HH24:MI:SS') ||
                     USER || USERENV('SESSIONID'));
            ELSE
                -- need to generate 55 more results
                FOR i IN 0..30 LOOP
                    randval := mem(i+24) + mem(i);
                    IF (randval >= 1.0) THEN
                        randval := randval - 1.0;
                    END IF;
                    mem(i) := randval;
                END LOOP;
                FOR i IN 31..54 LOOP
                    randval := mem(i-31) + mem(i);
                    IF (randval >= 1.0) THEN
                        randval := randval - 1.0;
                    END IF;
                    mem(i) := randval;
                END LOOP;
            END IF;
            counter := 0;
        END IF;
        RETURN mem(counter);
    END value;


    -- Random 38-digit number between LOW and HIGH.
    FUNCTION value ( low in NUMBER, high in NUMBER) RETURN NUMBER
                   PARALLEL_ENABLE is
    BEGIN
        RETURN (value*(high-low))+low;
    END value;


    -- Random numbers in a normal distribution.
    -- Pilfered from Knuth volume 2.
    FUNCTION normal RETURN NUMBER PARALLEL_ENABLE is
                    -- 38 decimal places: Mean 0, Variance 1
        v1  NUMBER;
        v2  NUMBER;
        r2  NUMBER;
        fac NUMBER;
    BEGIN
        IF saved_norm is not NULL THEN     -- saved from last time
            v1 := saved_norm;              -- to be returned this time
            saved_norm := NULL;
        ELSE
            r2 := 2;
            -- Find two independent uniform variables
            WHILE r2 > 1 OR r2 = 0 LOOP
                v1 := value();
                v1 := v1 + v1 - 1;
                v2 := value();
                v2 := v2 + v2 - 1;
                r2 := v1*v1 + v2*v2;  -- r2 is radius
            END LOOP;      -- 0 < r2 <= 1:  in unit circle
            /* Now derive two independent normally-distributed variables */
            fac := sqrt(-2*ln(r2)/r2);
            v1 := v1*fac;          -- to be returned this time
            saved_norm := v2*fac;  -- to be saved for next time
        END IF;
        RETURN v1;
    END  normal;


    -- Random string.  Pilfered from Chris Ellis.
    FUNCTION string (opt char, len NUMBER)
        RETURN VARCHAR2 PARALLEL_ENABLE is      -- string of <len> characters
        optx char (1)  := lower(opt);
        rng  NUMBER;
        n    BINARY_INTEGER;
        ccs  VARCHAR2 (128);    -- candidate character subset
        xstr VARCHAR2 (4000) := NULL;
    BEGIN
        IF    optx = 'u' THEN    -- upper case alpha characters only
            ccs := 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
            rng := 26;
        ELSIF optx = 'l' THEN    -- lower case alpha characters only
            ccs := 'abcdefghijklmnopqrstuvwxyz';
            rng := 26;
        ELSIF optx = 'a' THEN    -- alpha characters only (mixed case)
            ccs := 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ||
                  'abcdefghijklmnopqrstuvwxyz';
            rng := 52;
        ELSIF optx = 'x' THEN    -- any alpha-numeric characters (upper)
            ccs := '0123456789' ||
                  'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
            rng := 36;
        ELSIF optx = 'p' THEN    -- any printable char (ASCII subset)
            ccs := ' !"#$%&''()*+,-./' || '0123456789' || ':;<=>?@' ||
                  'ABCDEFGHIJKLMNOPQRSTUVWXYZ' || '[\]^_`' ||
                  'abcdefghijklmnopqrstuvwxyz' || '{|}~' ;
            rng := 95;
        ELSE
            ccs := 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
            rng := 26;          -- default to upper case
        END IF;
        FOR i IN 1 .. least(len,4000) LOOP
            /* Get random integer within specified range */
            n := TRUNC(rng * value) + 1;
            /* Append character to string  */
            xstr := xstr || SUBSTR(ccs,n,1);
        END LOOP;
        RETURN xstr;
    END string;

    -- For compatibility with 8.1
    PROCEDURE initialize(val IN BINARY_INTEGER) IS
    BEGIN
	seed(to_char(val));
    END initialize;


    -- For compatibility with 8.1
    -- Random binary_integer, -power(2,31) <= Random < power(2,31)
    -- Delayed Fibonacci, pilfered from Knuth volume 2
    FUNCTION random RETURN BINARY_INTEGER PARALLEL_ENABLE IS
    BEGIN
	RETURN TRUNC(Value*4294967296)-2147483648;
    END random;


    -- For compatibility with 8.1
    PROCEDURE terminate IS
    BEGIN
	NULL;
    END terminate;

END dbms_random;


-- TRIGGERS

create or replace
TRIGGER DEPT_TRIGGER_TEST
BEFORE INSERT ON DEPT
FOR EACH ROW
BEGIN
  SELECT :new.deptno INTO :new.deptno FROM dual;
END;

create or replace
TRIGGER EMP_TRIGGER_TEST
BEFORE INSERT ON EMP
FOR EACH ROW
BEGIN
  SELECT :new.empno INTO :new.empno FROM dual;
END;

commit;


-- INFORMATIONS
analyze table dept compute statistics;
analyze table emp compute statistics;
analyze table bonus compute statistics;
analyze table salgrade compute statistics;